package com.my.stock.core;

import java.io.IOException;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics;

import util.JavaFile;

public class DataProcess {
	private static Map<String, Product> productMap = new HashMap<String, Product>();

	public static void main(String[] args) throws IOException, InterruptedException {

		List<String> config = JavaFile.readfile("d:\\show.txt");
		for (String c : config) {
			// System.out.println(c);
			Product p = new Product();
			p.setCode(c.split(",")[0]);
			p.setContractName(c.split(",")[1]);
			p.setMaxOrderNum(Integer.parseInt(c.split(",")[3]));
			p.setMinStep(Double.parseDouble(c.split(",")[4]));
			p.setUnit(Integer.parseInt(c.split(",")[5]));
			p.setStrategy(c.split(",")[6]);
			p.setStopLossStep(Integer.parseInt(c.split(",")[7]));
			p.setTriggerVolume(Double.parseDouble(c.split(",")[8]));
			p.setTriggerNeed(Integer.parseInt(c.split(",")[9]));
			p.setStopMovingNeed(Integer.parseInt(c.split(",")[10]));
			p.setFrom(c.split(",")[12]);
			productMap.put(c.split(",")[1], p);
//			System.out.println(p.getContractName());
			buyOrSell(p.getContractName());
		}

//		buy("i2501");
//		sell("i2501");
//
//		buy("i2505");
//		sell("i2505");

//

//		for (int j = 1; j < 5; j++) {
//			for (int i = 1; i < 5; i++) {
//				System.out.println(i + "  " + j);
////				buyOrSell("c2501", "c2501_1", i, j, 10, 10, 1, "buy", "", "", 1);
//				buyOrSell("i2501", "i2501", i*0.5, j*0.5, 100, 10, 1, "buy", "", "", 0.5);
//			}
//		}

//		buyOrSell("c2501", "c2501_1", 4, 2, 10, 10, 1, "buy", "", "20241008", "", 1);
//		buyOrSell("c2501", "c2501_1", 4, 2, 10, 10, 1, "sell", "", "20241008", "", 1);
//
//		buyOrSell("c2501", "c2501", 4, 2, 10, 10, 1, "buy", "20241008", "", "", 1);
//		buyOrSell("c2501", "c2501", 4, 2, 10, 10, 1, "sell", "20241008", "", "", 1);

	}

	HashMap<Double, Double> priceVol = new HashMap<Double, Double>();

	double lastbuyPrice = -1;
	double lastsellPrice = -1;
	double lastaskVol = -1;
	double lastbidVol = -1;
	double lastvol = -1;
	double llastvol = -1;
	double lastturnover = -1;

	double lastinterest = -1;
	double llastinterest = -1;
	double lastaPrice = -1;
	double lastaveragePrice = -1;
	int count = 0;
	int buy = 0;
	int sell = 0;

	int continueUp = 0;
	int continueDown = 0;

	private static boolean dataClear(double lastPrice, String dateDay, String date) {
		if (lastPrice <= 0) {
			return true;
		}
//		if (!dateSelected.equals(dateDay)) {
//			return true;
//		}
		if (date.startsWith("08") || date.startsWith("15") || date.startsWith("20") || date.startsWith("03")) {
			return true;
		}

		return false;
	}

	private static void timeLineAllInfo(List<String> slist, String from, Product p) throws InterruptedException {

		LocalDateTime firstTime = null;
		double first5minsHighTick = -1;
		double first5minsLowTick = -1;
		double lvol = 0;
		double lturn = 0;
		double lint = 0;
		double lava = 0;
		double lbuyPrice = 0;
		double lsellPrice = 0;
		String newDateDay = "";

		Map<Double, Double> priceBidMap = new HashMap<Double, Double>();
		Map<Double, Double> priceAskMap = new HashMap<Double, Double>();
		DescriptiveStatistics tr5mins = new DescriptiveStatistics();

		DescriptiveStatistics vol5mins = new DescriptiveStatistics();
		DescriptiveStatistics ask5mins = new DescriptiveStatistics();
		DescriptiveStatistics bid5mins = new DescriptiveStatistics();
		List<DescriptiveStatistics> vol5minsList = new ArrayList<DescriptiveStatistics>();
		List<DescriptiveStatistics> ask5minsList = new ArrayList<DescriptiveStatistics>();
		List<DescriptiveStatistics> bid5minsList = new ArrayList<DescriptiveStatistics>();
		List<String> dateList = new ArrayList<String>();
		boolean begin = false;
		for (int i = 0; i < slist.size(); i++) {
			String s = slist.get(i);
			String data[] = s.split(",");

			double buyPrice = Double.parseDouble(data[3]);
			double sellPrice = Double.parseDouble(data[2]);

			double askVol = Double.parseDouble(data[7]);
			double bidVol = Double.parseDouble(data[8]);
			double turnover = Double.parseDouble(data[9]);
			double vol = Double.parseDouble(data[10]);
			double interest = Double.parseDouble(data[11]);

			double avaragePrice = (turnover - lturn) / (vol - lvol) / p.getUnit();

//			System.out.println(sellPrice + " " + askVol);
//			System.out.println(buyPrice + " " + bidVol);
//			System.out.println(vol - lvol);
//			System.out.println(avaragePrice);
//			System.out.println(interest);

			if (buyPrice != lbuyPrice) {
				if (buyPrice > lbuyPrice) {
					if (priceBidMap.get(buyPrice) == null || priceBidMap.get(buyPrice) == 0) {
//						System.out.println(
//								"买家提高" + ((buyPrice - lbuyPrice) / p.getMinStep()) + "个价位 " + "增单:" + bidVol + "手");
					}
				} else {
					if (vol - lvol > 0) {
						if (avaragePrice != lbuyPrice) {
							// System.out.println("幽灵单撤单:" + priceBidMap.get(lbuyPrice) + "手");
						} else {

							if (avaragePrice > lava) {
								// System.out.println("买家扫单" + ((lbuyPrice - buyPrice) / p.getMinStep()) + "个价位
								// " + "成交"
								// + (vol - lvol) + "手++++++++++++++++++++++++++++");
								for (int xx = 0; xx < (vol - lvol); xx++) {
									System.out.print("★");
								}
								System.out.println("");
								System.out.println(sellPrice + " " + askVol);
								System.out.println(buyPrice + " " + bidVol);
							}

							else if (avaragePrice < lava) {
								// System.out.print("卖家扫单" + ((lbuyPrice - buyPrice) / p.getMinStep()) + "个价位 "
								// + "成交"
								// + (vol - lvol)
								// + "手 -----------------------------------------------------------");
								for (int xx = 0; xx < (vol - lvol); xx++) {
									System.out.print("✰");
								}
								System.out.println("");
								System.out.println(sellPrice + " " + askVol);
								System.out.println(buyPrice + " " + bidVol);
							}
						}
					} else {
//						System.out.println("幽灵单撤单:" + priceBidMap.get(lbuyPrice) + "手");

					}
					priceBidMap.put(lbuyPrice, 0.0);
				}
			}

			if (sellPrice != lsellPrice) {
				if (sellPrice > lsellPrice) {
					if (vol - lvol > 0) {
						if (avaragePrice != lsellPrice) {
							// System.out.println("幽灵单撤单:" + priceAskMap.get(lsellPrice) + "手");

						}
						if (avaragePrice > lava) {
//							System.out.println("买家扫单" + ((sellPrice - lsellPrice) / p.getMinStep()) + "个价位 " + "成交"
//									+ (vol - lvol) + "手++++++++++++++++++++++++++++");

							for (int xx = 0; xx < (vol - lvol); xx++) {
								System.out.print("★");
							}
							System.out.println("");
							System.out.println(sellPrice + " " + askVol);
							System.out.println(buyPrice + " " + bidVol);
						} else if (avaragePrice < lava) {
							// System.out.print("卖家扫单" + ((sellPrice - lsellPrice) / p.getMinStep()) + "个价位
							// " + "成交"
							// + (vol - lvol) + "手
							// -----------------------------------------------------------");
							for (int xx = 0; xx < (vol - lvol); xx++) {
								System.out.print("✰");
							}
							System.out.println("");
							System.out.println(sellPrice + " " + askVol);
							System.out.println(buyPrice + " " + bidVol);
						}

					} else {
						// System.out.println("幽灵单撤单:" + priceAskMap.get(lsellPrice) + "手");
					}
					priceAskMap.put(lsellPrice, 0.0);
				} else {

					if (priceAskMap.get(sellPrice) == null || priceAskMap.get(sellPrice) == 0) {
//						System.out.println(
//								"卖家降低" + ((lsellPrice - sellPrice) / p.getMinStep()) + "个价位  " + "增单:" + askVol + "手");
					}
				}
			}

			// 有成交量
			if (vol - lvol > 0) {
				// 持仓量未变
				if (interest == lint) {
					if (priceAskMap.get(sellPrice) != null) {
						if (priceAskMap.get(sellPrice) == askVol - (vol - lvol)) {

						} else if (priceAskMap.get(sellPrice) > askVol - (vol - lvol)) {
							// System.out.println("卖家撤单:" + (priceAskMap.get(sellPrice) - askVol - (vol -
							// lvol)));
						} else if (priceAskMap.get(sellPrice) < askVol - (vol - lvol)) {
							// System.out.println("卖家增单:" + (askVol - priceAskMap.get(sellPrice) + (vol -
							// lvol)));
						}
					}
					if (priceBidMap.get(buyPrice) != null) {
						if (priceBidMap.get(buyPrice) == bidVol - (vol - lvol)) {

						} else if (priceBidMap.get(buyPrice) > bidVol - (vol - lvol)) {
							// System.out.println("买家撤单:" + (priceBidMap.get(buyPrice) - bidVol - (vol -
							// lvol)));
						} else if (priceBidMap.get(buyPrice) < bidVol - (vol - lvol)) {
							// System.out.println("买家增单:" + (bidVol - priceBidMap.get(buyPrice) + (vol -
							// lvol)));
						}
					}

					if (avaragePrice == sellPrice) {
						// System.out.println("多仓换手：" + (vol - lvol) + "手");

					} else if (avaragePrice == buyPrice) {
						// System.out.println("空仓换手：" + (vol - lvol) + "手");

					} else {
						// System.out.println("各有换手");
					}

				}
				// 持仓量下降
				else if (interest < lint) {

					if (vol - lvol != lint - interest) {
						// System.out.println((lint - interest) + "手平仓" + (vol - lvol - lint + interest)
						// + "手换手");
					} else {
//						if (avaragePrice > lava) {
//							System.out.print("买家扫单++++++++++++++++++++++++++++++++++++ ");
//						} else if (avaragePrice < lava) {
//							System.out.print("卖家扫单 -----------------------------------------------------------");
//						}
//						System.out.println("仓单平仓" + (lint - interest) + "手");

					}

				}
				// 持仓量上升
				else if (interest > lint) {
					if (vol - lvol != interest - lint) {
//						System.out.println((interest - lint) + "手平仓" + (vol - lvol + lint - interest) + "手换手");
					} else {
//						System.out.println("仓单加仓" + (interest - lint) + "手");
					}

				}
			} else {
				if (priceBidMap.get(buyPrice) != null) {
					if (priceBidMap.get(buyPrice) == bidVol) {

					} else if (priceBidMap.get(buyPrice) > bidVol) {
//						System.out.println("买家撤单:" + (priceBidMap.get(buyPrice) - bidVol) + "手");
					} else if (priceBidMap.get(buyPrice) < bidVol) {
//						System.out.println("买家增单:" + (bidVol - priceBidMap.get(buyPrice)) + "手");
					}
				}
				if (priceAskMap.get(sellPrice) != null) {
					if (priceAskMap.get(sellPrice) == askVol) {

					} else if (priceAskMap.get(sellPrice) > askVol) {
//						System.out.println("卖家撤单:" + (priceAskMap.get(sellPrice) - askVol) + "手");
					} else if (priceAskMap.get(sellPrice) < askVol) {
//						System.out.println("卖家增单:" + (askVol - priceAskMap.get(sellPrice)) + "手");
					}
				}

			}
			// System.out.println("");
			double lastPrice = Double.parseDouble(data[1]);
			Thread.sleep(1);
			String date = data[6].split("#")[1];
			String dateDay = data[6].split("#")[0];

//			if (begin == false) {
//				if (dateDay.startsWith("20241014")) {
//					begin = true;
//				} else {
//					continue;
//				}
//			}

			if (!newDateDay.equals(dateDay)) {
				newDateDay = dateDay;
				vol5minsList = new ArrayList<DescriptiveStatistics>();
				ask5minsList = new ArrayList<DescriptiveStatistics>();
				bid5minsList = new ArrayList<DescriptiveStatistics>();
				tr5mins = new DescriptiveStatistics();
				dateList = new ArrayList<String>();
			}
//			System.out.println(newDateDay);

			if (dataClear(lastPrice, dateDay, date)) {
				continue;
			}
//			System.out.println(s);
			ask5mins.addValue(askVol);
			bid5mins.addValue(bidVol);
			vol5mins.addValue(vol - lvol);

			if (firstTime == null) {
				first5minsHighTick = lastPrice;
				first5minsLowTick = lastPrice;
				firstTime = LocalDateTime.of(Integer.parseInt(dateDay.substring(0, 4)),
						Integer.parseInt(dateDay.substring(4, 6)), Integer.parseInt(dateDay.substring(6, 8)),
						Integer.parseInt(date.split(":")[0]), Integer.parseInt(date.split(":")[1]),
						Integer.parseInt(date.split(":")[2]), Integer.parseInt(data[6].split("#")[2]));

//				if (Integer.parseInt(date.split(":")[0]) > 15) {
//					firstTime = firstTime.plusDays(-1);
//				}

			} else {

				if (lastPrice > first5minsHighTick) {
					first5minsHighTick = lastPrice;
				}
				if (lastPrice < first5minsLowTick) {
					first5minsLowTick = lastPrice;
				}

				LocalDateTime newTime = LocalDateTime.of(Integer.parseInt(dateDay.substring(0, 4)),
						Integer.parseInt(dateDay.substring(4, 6)), Integer.parseInt(dateDay.substring(6, 8)),
						Integer.parseInt(date.split(":")[0]), Integer.parseInt(date.split(":")[1]),
						Integer.parseInt(date.split(":")[2]), Integer.parseInt(data[6].split("#")[2]));

//				if (from.equals("zz") && Integer.parseInt(date.split(":")[0]) > 15) {
//					newTime = newTime.plusDays(-1);
//				}

				if (newTime.getMinute() != firstTime.getMinute() && newTime.getMinute() % 1 == 0) {
					tr5mins.addValue(first5minsHighTick - first5minsLowTick);

					vol5minsList.add(vol5mins);
					ask5minsList.add(ask5mins);
					bid5minsList.add(bid5mins);
					dateList.add(newTime.getHour() + " " + newTime.getMinute());
//					System.out.println(newTime);
//					System.out.println(first5minsHighTick - first5minsLowTick);
					firstTime = newTime;
					first5minsHighTick = lastPrice;
					first5minsLowTick = lastPrice;

					vol5mins = new DescriptiveStatistics();
					ask5mins = new DescriptiveStatistics();
					bid5mins = new DescriptiveStatistics();

				}

			}

			if ((vol - lvol) != 0) {
				lava = avaragePrice;
			}

			lvol = vol;
			lturn = turnover;
			lint = interest;
			lbuyPrice = buyPrice;
			lsellPrice = sellPrice;

			priceBidMap.put(buyPrice, bidVol);
			priceAskMap.put(sellPrice, askVol);
			if (dateDay.equals("20241009")) {

			} else {
				infoMap.put(p.getCode() + dateDay + "vol", vol5minsList);
				infoMap.put(p.getCode() + dateDay + "ask", ask5minsList);
				infoMap.put(p.getCode() + dateDay + "bid", bid5minsList);
				dateMap.put(p.getCode() + dateDay, dateList);
				trMap.put(p.getCode() + dateDay, tr5mins);
			}

		}

	}

	private static Map<String, List<DescriptiveStatistics>> infoMap = new HashMap<String, List<DescriptiveStatistics>>();
	private static Map<String, List<String>> dateMap = new HashMap<String, List<String>>();
	private static Map<String, DescriptiveStatistics> trMap = new HashMap<String, DescriptiveStatistics>();

	public static void buyOrSell(String product) throws IOException, InterruptedException {
		String arr[] = { "buy", "sell" };

		Product p = productMap.get(product);

		String code = p.getCode();

		double unit = p.getUnit();

		double minpriceStep = p.getMinStep();

//		File file = new File("d:\\" + code + buyOrSell + ".txt");
//		file.deleteOnExit();
//		JavaFile.overwritefile("d:\\" + code + buyOrSell + ".txt", "");

		HashMap<Double, Double> priceVol = new HashMap<Double, Double>();

		List<String> slist = JavaFile.readfile("d:\\tick\\" + code + ".txt");

		timeLineAllInfo(slist, p.getFrom(), p);
		for (int xx = 2; xx < 5; xx++) {

			boolean printFlag = false;
			double lastbuyPrice = -1;
			double lastsellPrice = -1;
			double lastaskVol = -1;
			double lastbidVol = -1;
			double lastvol = -1;
			double llastvol = -1;
			double lastturnover = -1;

			double lastinterest = -1;
			double llastinterest = -1;
			double lastaPrice = -1;
			double lastaveragePrice = -1;
			double aPrice = -1;

			int continueUp = 0;
			int continueDown = 0;
			TimelineUtil timeLineUtilWin = new TimelineUtil();

			String dateSelected = DateUtil.getDates(xx * -1);

			if ("".equals(dateSelected)) {
				continue;
			}

			System.out.print(p.getCode() + "  " + dateSelected + "  ");
			double highPrice = -1;
			double lowPrice = 999999999;
			int d = 0;
//			int d = (int) (win5mins.getMean() * 1 / minpriceStep);
			double loss = d * minpriceStep;

			double win = loss * 2;
			for (String buyOrSell : arr) {

				for (int i = 0; i < slist.size(); i++) {
					String s = slist.get(i);
					String data[] = s.split(",");
//				System.out.println(s);
					double buyPrice = Double.parseDouble(data[3]);
					if (buyPrice <= 0) {
						continue;
					}

					double sellPrice = Double.parseDouble(data[2]);
					String date = data[6].split("#")[1];
					String dateDay = data[6].split("#")[0];

					if (!dateSelected.equals(dateDay)) {
						continue;
					}
					if (buyPrice > highPrice) {
						highPrice = buyPrice;
					}

//					System.out.println(s);
					if (buyPrice < lowPrice) {
						lowPrice = buyPrice;
					}

//				if (!"".equals(time) && !date.startsWith(time)) {
//					continue;
//				}

					double askVol = Double.parseDouble(data[7]);
					double bidVol = Double.parseDouble(data[8]);
					double turnover = Double.parseDouble(data[9]);
					double vol = Double.parseDouble(data[10]);
					double interest = Double.parseDouble(data[11]);

					double lastupdatePrice = Double.parseDouble(data[14]);

					double averagePrice = Double.parseDouble(data[13]);

					int dateMin = Integer.parseInt(date.split(":")[1]) / 15;

					String dateUse = date.split(":")[0] + dateMin;

					double currentTurnover = turnover - lastturnover;
					double currentVol = vol - lastvol;
					aPrice = currentTurnover / currentVol / unit;
					double doBuy = -1;
					double doSell = -1;

					if (vol == lastvol || currentVol < 0) {
						// (buyPrice == lastbuyPrice && sellPrice == lastsellPrice) ||
					} else {

						String print = "";
						String signal = ",^^^^^^^";
//					System.out.println(i);
						for (int j = i + 1; j < slist.size(); j++) {
							String dataFuture[] = slist.get(j).split(",");
							double buyPriceFuture = Double.parseDouble(dataFuture[3]);
							double sellPriceFuture = Double.parseDouble(dataFuture[2]);

//							System.out.println(sellPrice - buyPriceFuture);

//						i = j - 1;
							if (buyOrSell.equals("sell")) {
								if (sellPrice - sellPriceFuture <= -1.0 * loss) {
//								System.out.println("开仓价格 " + sellPrice + "     止损价格 " + sellPriceFuture + "--------");
									signal = ",-------";
									timeLineUtilWin.insertData(-1.0);
									break;
								} else if (buyPrice - buyPriceFuture >= win) {
//								System.out.println("开仓价格 " + buyPrice + "     止赢价格 " + buyPriceFuture + "+++++++++++");
									signal = ",+++++++";
									timeLineUtilWin.insertData(2.0);
									break;
								}
							} else {
								if (buyPrice - buyPriceFuture >= loss) {
//								System.out.println("开仓价格 " + buyPrice + "     止损价格 " + buyPriceFuture + "--------");
									signal = ",-------";
									timeLineUtilWin.insertData(-1.0);
									break;
								} else if (sellPrice - sellPriceFuture <= -1.0 * win) {
//								System.out.println("开仓价格 " + sellPrice + "     止赢价格 " + sellPriceFuture + "+++++++++++");
									signal = ",+++++++";
									timeLineUtilWin.insertData(2.0);
									break;
								}
							}
						}

						if (signal.equals(",^^^^^^^")) {
							continue;
						}

						if (buyPrice - lastbuyPrice != 0 || sellPrice - lastsellPrice != 0) {

							if (sellPrice - lastsellPrice > 0 && buyPrice - lastbuyPrice < 0) {
//							System.out.println("$$");
							}

							if (sellPrice - lastsellPrice > 0) {
								if (continueDown < 0) {
									continueDown = 0;
								}
								continueUp++;
							}

							if (buyPrice - lastbuyPrice < 0) {
								if (continueUp > 0) {
									continueUp = 0;
								}
								continueDown--;
							}

//						System.out.println(continueUp + "  " + continueDown);

						}

//						System.out.println(continueUp + "  " + continueDown);

//					minpriceStep*

						if (aPrice % minpriceStep == 0) {

							if ((continueUp + continueDown) > 0) {
								doBuy = currentVol;
								doSell = 0;
							} else if ((continueUp + continueDown) < 0) {
								doSell = currentVol;
								doBuy = 0;
							} else {
								System.out.println(":");

							}

							priceVolProcess(priceVol, aPrice, currentVol);
//						System.out.println(currentVol);
						} else {

							double b = (lastupdatePrice * currentVol * unit - currentTurnover) / (minpriceStep * unit);

							if (Math.abs(b - currentVol) > 10000) {

							} else {
								while (Math.abs(b) > currentVol) {
									if (b > 0) {
										lastupdatePrice = lastupdatePrice - minpriceStep;
									} else {
										lastupdatePrice = lastupdatePrice + minpriceStep;
									}

									b = (lastupdatePrice * currentVol * unit - currentTurnover) / (minpriceStep * unit);
								}

								double a = currentVol - Math.abs(b);
								if (b > 0) {
//								System.out.println((currentVol + "       " + lastupdatePrice * currentVol + "         " + a
//										+ "       " + b + "         " + (b * (lastupdatePrice - 0.5) + a * lastupdatePrice))
//										+ "        " + currentTurnover / 100);

									priceVolProcess(priceVol, (lastupdatePrice - minpriceStep), b);
									priceVolProcess(priceVol, lastupdatePrice, a);

//								System.out.println("cc");

								} else {
//								System.out.println(
//										(currentVol + "       " + lastupdatePrice * currentVol + "         " + +a + "       "
//												+ b + "         " + (-1 * b * (lastupdatePrice + 0.5) + a * lastupdatePrice))
//												+ "        " + currentTurnover / 100);
									priceVolProcess(priceVol, (lastupdatePrice + minpriceStep), -1 * b);
									priceVolProcess(priceVol, lastupdatePrice, a);
//								System.out.println("cc");
								}

								if ((continueUp + continueDown) > 0) {
									if (Math.abs(a) >= Math.abs(b)) {
										doBuy = Math.abs(a);
										doSell = Math.abs(b);
									} else {
										doBuy = Math.abs(b);
										doSell = Math.abs(a);
									}
								} else if ((continueUp + continueDown) < 0) {
									if (Math.abs(a) >= Math.abs(b)) {
										doBuy = Math.abs(b);
										doSell = Math.abs(a);
									} else {
										doBuy = Math.abs(a);
										doSell = Math.abs(b);
									}
								} else {
									System.out.println(":");

								}

							}

						}

						print = (averagePrice - lastaveragePrice) + "," + (doBuy - doSell) + ","
								+ getPriceVol(priceVol, buyPrice) + "," + getPriceVol(priceVol, sellPrice) + ","
								+ (continueUp + continueDown) + "," + averagePrice + "," + lastaskVol + "," + lastbidVol
								+ "," + (lastbidVol - lastaskVol) + "," + currentVol + ","
								+ ((interest - lastinterest) + "," + dateUse + signal);

						if (print.equals("")) {
							continue;
						}

						if (printFlag) {

							if (Math.abs((averagePrice - lastaveragePrice)) > minpriceStep * p.getUnit()
									|| dateUse.startsWith("08") || dateUse.startsWith("15")) {
								// 异常数据不记录
								if (Math.abs((averagePrice - lastaveragePrice)) > minpriceStep * p.getUnit()) {
//								System.out.println(print);
								}

							} else {
//								JavaFile.writefile("d:\\" + p.getCode() + "_" + buyOrSell + "_output.txt",
//										print + "\r\n");
							}

						} else {
							printFlag = true;
						}
					}

//				if (dateUse.equals("090") || dateUse.equals("210")) {
//					continue;
//				}

					lastbuyPrice = buyPrice;
					lastsellPrice = sellPrice;

					llastinterest = (interest - lastinterest);
					lastaskVol = askVol;
					lastbidVol = bidVol;
					llastvol = (vol - lastvol);
					lastvol = vol;
					lastinterest = interest;
					lastturnover = turnover;
					lastaPrice = aPrice;
					lastaveragePrice = averagePrice;

//				System.out.println(
//						buyOrSell + " 1min " + timeLineUtilWin.getOneMinsCount() / timeLineUtilWin.getOneMinsSize());
//				System.out.println(
//						buyOrSell + " 3min " + timeLineUtilWin.getThreeMinsCount() / timeLineUtilWin.getThreeMinsSize());
//				System.out.println(
//						buyOrSell + " 5min " + timeLineUtilWin.getFiveMinsCount() / timeLineUtilWin.getFiveMinsSize());
//				System.out.println(
//						buyOrSell + " 10min " + timeLineUtilWin.getTenMinsCount() / timeLineUtilWin.getTenMinsSize());

				}

				if (timeLineUtilWin.getTotalListSize() == 0) {
					continue;
				}
//				System.out.print(
//						buyOrSell + " total " + timeLineUtilWin.getTotalCount() / timeLineUtilWin.getTotalListSize()
//								+ "    size " + timeLineUtilWin.getTotalListSize() + "  ");

			}
//			if (highPrice > -1) {
//				System.out.println(highPrice + " " + lowPrice + " tr: " + (Math.abs(highPrice - lowPrice)) + " loss:"
//						+ loss + " tr/loss:" + ((Math.abs(highPrice - lowPrice)) / loss));
//			}

		}
		for (int i = 0; i < 100; i++) {

			for (int j = 1; j < 50; j++) {
				String dateSelected = DateUtil.getDates(j * -1);
				try {
					if (infoMap.get(p.getCode() + dateSelected + "vol") == null
							|| infoMap.get(p.getCode() + dateSelected + "vol").get(i) == null) {
						continue;
					}

				} catch (java.lang.IndexOutOfBoundsException e) {
					continue;
				}

				System.out.println(
						p.getCode() + "日期:" + dateSelected + " " + dateMap.get(p.getCode() + dateSelected).get(i) + " "
								+ infoMap.get(p.getCode() + dateSelected + "vol").get(i).getPercentile(75) + " "
								+ infoMap.get(p.getCode() + dateSelected + "vol").get(i).getMax() + " "
								+ infoMap.get(p.getCode() + dateSelected + "ask").get(i).getPercentile(75) + " "
								+ infoMap.get(p.getCode() + dateSelected + "bid").get(i).getPercentile(75) + " "
								+ trMap.get(p.getCode() + dateSelected).getElement(i));
			}
			System.out.println("");
		}

	}

	private static void priceVolProcess(HashMap<Double, Double> priceVolMap, double price, double vol) {

		if (vol == 0) {
			return;
		} else if (vol < 0) {
			System.out.print("error??????");
		}

		if (priceVolMap.get(price) == null) {
			priceVolMap.put(price, vol);
		} else {
			double volPlus = priceVolMap.get(price) + vol;
			priceVolMap.put(price, volPlus);
		}
	}

	private static double getPriceVol(HashMap<Double, Double> priceVolMap, double price) {

		Double returnVol = priceVolMap.get(price);
		if (returnVol == null) {
			return 0;
		} else {
			return returnVol;
		}
	}

}
